package com.example.emos.api.service.impl;

import com.example.emos.api.common.util.PageUtils;
import com.example.emos.api.db.dao.TbModelDao;
import com.example.emos.api.db.dao.TbPackMangerDao;
import com.example.emos.api.db.pojo.TbPackManger;
import com.example.emos.api.service.ModelService;
import com.example.emos.api.service.PackMangerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;

@Service
public class PackMangerServiceImpl implements PackMangerService {
    @Autowired
    TbPackMangerDao tbPackMangerDao;
    @Override
    public PageUtils searchPackByPage(HashMap param) {
        ArrayList<HashMap> list= tbPackMangerDao.searchPackByPage(param);
        long count=tbPackMangerDao.searchPackMangerCount(param);
        int start=(Integer) param.get("start");
        int length=(Integer) param.get("length");
        PageUtils pageUtils=new PageUtils(list,count,start,length);
        return pageUtils;
    }

    @Override
    public int insertPack(TbPackManger pack) {
        HashMap map=new HashMap();
        map.put("deviceName",pack.getDeviceName());
       int c= tbPackMangerDao.countByDeviceName(map);
       if(c>0){
           return -1;
       }else{

           int row= tbPackMangerDao.insert(pack);
           return row;
       }
    }

    @Override
    public HashMap selectByPrimaryKey(Integer id) {
        return tbPackMangerDao.selectByPrimaryKey(id);
    }

    @Override
    public HashMap selectByName(String params) {
        return tbPackMangerDao.selectByName(params);
    }

    @Override
    public int update(HashMap params) {
        return tbPackMangerDao.update(params);
    }
}
